#!/usr/bin/env python3
# -*- coding: utf-8 -*-

"""
账本 - 商户分账开通功能使用示例
"""

from examples.base_example import BaseExample
from jlpay.services.ledger.merchconf_service import MerchconfService
from jlpay.model.ledger.merchconf import MerchIssueOpenRequest


class MerchIssueOpenExample(BaseExample):
    """商户分账开通示例类"""
    
    def __init__(self):
        """初始化示例类"""
        super().__init__("examples.ledger.merchconf.issue_open")
        self.service = MerchconfService(self.config)
    
    def build_merch_issue_open_request(self):
        """构建商户分账开通请求"""
        request = MerchIssueOpenRequest()
        
        # 设置请求参数
        request.set_org_code("50720711")
        request.set_mch_id("849581183510017")
        request.set_ledger_module("02")
        request.set_max_split_rate("20")
        request.set_source_ids(["jlpay/2024-08-30/e22bc590f433418483626fded04f3362.png", "jlpay/2024-08-30/e22bc590f433418483626fded04f3363.png"])
        request.set_fee_rate("2")
        request.set_pbthf("0")
        request.set_low_amt("1")
        request.set_up_amt("10")
        request.set_notify_url("https://api.mch.weixin.qq.com/sns/notify")
        
        return request
    
    def demo(self):
        """执行商户分账开通示例"""
        self.logger.info("开始执行商户分账开通示例")
        
        # 创建商户分账开通请求
        request = self.build_merch_issue_open_request()
        
        # 发送请求
        response = self.send_request_and_handle_response(
            self.service.open_merch_issue,
            "商户分账开通",
            request
        )
        
        # 处理响应结果
        if response and response.is_success():
            self.logger.info(f"响应报文：{response.to_dict()}")
        
        self.logger.info("商户分账开通示例执行完毕")


if __name__ == "__main__":
    example = MerchIssueOpenExample()
    example.logger.info("=" * 50)
    example.logger.info("===== 商户分账开通示例 开始 =====")
    example.logger.info("=" * 50)
    
    example.demo()
    
    example.logger.info("=" * 50)
    example.logger.info("===== 商户分账开通示例执行完毕 =====")
    example.logger.info("=" * 50) 